package com.yourcompany.web.controller;

import cn.dev33.satoken.stp.StpUtil;
import cn.dev33.satoken.util.SaResult;
import com.yourcompany.api.dto.MenuDTO;
import com.yourcompany.api.service.MenuService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Tag(name = "菜单管理")
@RestController
@RequestMapping("/api/menu")
public class MenuController {

    @Autowired
    private MenuService menuService;

    @Operation(summary = "创建菜单")
    @PostMapping
    public SaResult createMenu(@Validated @RequestBody MenuDTO menuDTO) {
        menuService.createMenu(menuDTO);
        return SaResult.ok();
    }

    @Operation(summary = "更新菜单")
    @PutMapping("/{id}")
    public SaResult updateMenu(@PathVariable Long id, @Validated @RequestBody MenuDTO menuDTO) {
        menuService.updateMenu(id, menuDTO);
        return SaResult.ok();
    }

    @Operation(summary = "删除菜单")
    @DeleteMapping("/{id}")
    public SaResult deleteMenu(@PathVariable Long id) {
        menuService.deleteMenu(id);
        return SaResult.ok();
    }

    @Operation(summary = "获取菜单树")
    @GetMapping("/tree")
    public SaResult getMenuTree() {
        return SaResult.ok().setData(menuService.getMenuTree());
    }

    @Operation(summary = "获取用户菜单")
    @GetMapping("/user")
    public SaResult getUserMenus() {
        return SaResult.ok().setData(menuService.getUserMenus());
    }
} 